package com.twu.driver;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.Library;
import com.twu.io.IOHandler;

import java.util.ArrayList;

/**
 * Created by vishwasdamle on 10/08/14.
 */
public class BookOperations {

    private Library library;
    private IOHandler io;

    public BookOperations(Library library) {
        this.library = library;
        io = new IOHandler();
    }

    public void returnBook() {

        io.displayString("Enter book name to return : ");
        try {
            library.returnBook(io.getString());
            io.displayString("Successful Return : Thank you for returning the book");
        } catch (Exception e) {
            io.displayString("Unsuccessful Return : That is not a valid book to return.");
        }
    }

    public void checkOutBook() {
        displayAvailableBooks();
        io.displayString("Enter Book name to check out : ");
        try {
            library.checkOutBook(io.getString());
            io.displayString("Successful Checkout : Thank you! Enjoy the Book!");
        } catch (Exception e) {
            io.displayString("Unsuccessful Checkout : That Book is not available.");
        }
    }

    public void displayAvailableBooks() {
        ArrayList<Book> availableBookList = library.getAvailableBookList();
        for(Book b : availableBookList) {
            io.displayString('\t' + b.toString());
        }
    }

}
